using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace MacomberMap.Common.Internals
{    /// <summary>
    /// This class provides an input box to the user (similar to VB style)
    /// </summary>
    public static class MM_InputBox
    {
        /// <summary>
        /// Offer a simple input box, a-la VB
        /// </summary>
        /// <param name="title"></param>
        /// <param name="promptText"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 10, 372, 13);
            label.AutoSize = true;            
            label.Text = promptText;
            form.Controls.Add(label);

            textBox.SetBounds(12, label.Bottom + 6, 372, 20);
            buttonOk.SetBounds(228, textBox.Bottom + 16, 75, 20);
            buttonCancel.SetBounds(309, textBox.Bottom + 16, 75, 20);
            
            
            form.Controls.AddRange(new Control[] { textBox, buttonOk, buttonCancel });
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;
            form.ClientSize = new Size(buttonCancel.Right+6, buttonOk.Bottom+6);
            DialogResult dialogResult = form.ShowDialog();
            if (dialogResult == DialogResult.OK)
                value = textBox.Text;

            form.Dispose();
            label.Dispose();
            textBox.Dispose();
            buttonOk.Dispose();
            buttonCancel.Dispose();
            return dialogResult;
        }
    }
}
